package com.kgc.service.edu.controller;


import com.github.pagehelper.PageInfo;
import com.kgc.common.result.Result;
import com.kgc.service.edu.entity.SieMenu;
import com.kgc.service.edu.entity.SieUser;
import com.kgc.service.edu.service.SieMenuService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/edu/sie-menu")
public class SieMenuController {
    private SieMenuService sieMenuService;

    public SieMenuController(SieMenuService sieMenuService) {
        this.sieMenuService = sieMenuService;
    }

    @PostMapping("{current}/{size}")
    @ApiOperation(value = "分页")
    public Result page(@ApiParam("当前页") @PathVariable("current") Integer current,
                       @ApiParam("每页显示条数") @PathVariable("size") Integer size
            , @ApiParam("查询对象") @RequestBody SieMenu sieMenu) {
        PageInfo<SieMenu> pageInfo = sieMenuService.selectSieMenu(sieMenu, current, size);

        // 1.获取总记录数
        long total = pageInfo.getTotal();
        // 2.获取所有数据
        List<SieMenu> sieMenus = pageInfo.getList();
       /* Map<String, Object> map = new HashMap();
        map.put("total", total);
        map.put("items", teachers);
        return Result.ok().setData(map);*/
        return Result.ok().setData("total", total).setData("items", sieMenus);
    }
    @DeleteMapping("{ids}")
    public Result delSieById(@RequestBody List<String> ids){

        int del=sieMenuService.delectMenuById(ids);
        return Result.ok().setData("item",del);
    }

    @GetMapping("/list")
    public Result list(){
        List<SieMenu> sieMenus= sieMenuService.tree();
        return Result.ok().setData("item",sieMenus);
    };
}
